import com.mongodb.BasicDBObject;
import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

public class MongoDemo1 {
    public static void main(String[] args) {
        MongoClient mongoClient = new MongoClient("192.168.221.135");
        MongoDatabase spitdb = mongoClient.getDatabase("spitdb");
        MongoCollection<Document> spit = spitdb.getCollection("spit");
        BasicDBObject bson = new BasicDBObject("userid", "1013");
        FindIterable<Document> documents = spit.find(bson);
        for (Document document : documents) {
            System.out.println(document.getString("content"));
            System.out.println(document.getString("userid"));
            System.out.println(document.getInteger("visits"));
        }
        mongoClient.close();
    }
}
